<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="所属工厂" prop="factoryId">
        <el-select
          v-model="queryParams.factoryId"
          placeholder="请选择所属工厂"
          clearable
          size="small"
        >
          <el-option
            v-for="dept in deptOptions"
            :key="dept.deptId"
            :label="dept.name"
            :value="dept.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="记录编号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入养护记录编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="记录名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入养护记录名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="养护级别" prop="level">
        <el-select
          v-model="queryParams.level"
          placeholder="请选择养护级别"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in levelOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="养护周期" prop="cycle">
        <el-select
          v-model="queryParams.cycle"
          placeholder="请选择养护周期"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in cycleOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker
          :editable="false"
          v-model="daterangeTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['equipment:process:add']"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      :data="processList"
      @selection-change="handleSelectionChange"
      max-height="550"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="所属工厂" align="center" prop="factoryName" />
      <el-table-column label="养护设备" align="center" prop="deviceName" />
      <el-table-column
        label="养护记录编号"
        align="center"
        prop="code"
        minWidth="100px"
      />
      <el-table-column
        label="养护记录名称"
        align="center"
        prop="name"
        minWidth="200px"
      />
      <el-table-column
        label="所属计划"
        align="center"
        prop="planName"
        minWidth="140px"
      />
      <el-table-column
        label="养护级别"
        align="center"
        prop="level"
        :formatter="levelFormat"
      />
      <el-table-column
        label="养护周期"
        align="center"
        prop="cycle"
        :formatter="cycleFormat"
        :width="$px2rem(80)"
      />
      <el-table-column
        label="养护人"
        align="center"
        prop="maintainPersonName"
        :width="$px2rem(70)"
      />

      <!--      <el-table-column label="保养时间" align="center" prop="maintainTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}") }}</span>
        </template>
      </el-table-column>-->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >
          <el-button
            v-if="scope.row.status == '01'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['equipment:process:edit']"
            >修改</el-button
          >
          <el-button
            v-if="scope.row.status == '01'"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['equipment:process:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改养护过程对话框 -->
    <el-dialog
      fullscreen
      :title="title"
      :visible.sync="open"
      width="900px"
      append-to-body
      destroy-on-close
      v-loading="isLoading"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属计划" prop="planId">
              <Dialog
                @dialogChange="planToProcess"
                :echoValue="form.planName"
                parameter="rows"
                value="id"
                label="name"
                search="code/name"
                url="/equipment/maintainPlan/list"
                :column="[
                  '计划编号/code',
                  '计划名称/name',
                  '所属工厂/factoryName',
                ]"
                placeholder="请选择计划"
                :openDisabled="openDisabled"
                :axiosData="{ status: 'Y' }"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="!openDisabled">
            <el-form-item label="养护结果" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in statusProcess"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                  >{{ dict.dictLabel }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="记录编号" prop="code">
              <el-input
                v-model="form.code"
                placeholder="请输入养护记录编号"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="记录名称" prop="name">
              <el-input
                v-model="form.name"
                placeholder="请输入养护记录名称"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属工厂" prop="factoryId">
              <el-select
                v-model="form.factoryId"
                placeholder="请选择所属工厂"
                clearable
                size="small"
                :disabled="openDisabled"
              >
                <el-option
                  v-for="dept in deptOptions"
                  :key="dept.deptId"
                  :label="dept.name"
                  :value="dept.deptId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="养护设备" prop="maintainDevice">
              <Dialog
                @dialogChange="form.maintainDevice = $event.value"
                :echoValue="form.deviceName"
                parameter="rows"
                value="id"
                label="name"
                search="code/name"
                url="/basic/eqpInfo/list"
                :column="['设备编号/code', '设备名/name']"
                :openDisabled="openDisabled"
                :multiple="true"
                placeholder="请选择养护设备"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="养护周期" prop="cycle">
              <el-select
                v-model="form.cycle"
                placeholder="请选择养护周期"
                :disabled="openDisabled"
              >
                <el-option
                  v-for="dict in cycleOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="养护级别" prop="level">
              <el-select
                v-model="form.level"
                placeholder="请选择养护级别"
                :disabled="openDisabled"
              >
                <el-option
                  v-for="dict in levelOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-col :span="12">
              <el-form-item label="养护时间" prop="maintainTime">
                <el-date-picker
                  @change="addTime"
                  :editable="false"
                  clearable
                  size="small"
                  v-model="form.maintainTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择养护时间"
                  :disabled="openDisabled"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否需要备件" prop="isSpareParts">
              <el-radio-group
                v-model="form.isSpareParts"
                :disabled="openDisabled"
              >
                <el-radio
                  v-for="dict in isSparePartsStatus"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                  >{{ dict.dictLabel }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.isSpareParts == 'Y'">
            <el-form-item label="申请备件记录" prop="outStockId">
              <Dialog
                @dialogChange="form.outStockId = $event.value"
                :echoValue="form.outStockName"
                parameter="rows"
                value="id"
                label="name"
                search="code/name"
                url="/equipment/inOutRecord/list"
                :column="['记录编号/code', '记录名称/name']"
                :openDisabled="false"
                placeholder="请选择养护设备"
                :axiosData="{ inOut: 'out' }"
              />
            </el-form-item>
          </el-col>
          <!--          <el-col :span="12">
            <el-form-item label="创建时间" prop="createTime">
              <el-date-picker
                :editable="false"
                clearable
                size="small"
                v-model="form.createTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm"
                format="yyyy-MM-dd HH:mm"
                :disabled="true"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>-->
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input
                v-model="form.remark"
                type="textarea"
                placeholder="请输入内容"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="center">养护过程内容信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddEqpMaintainProcessContent"
              :disabled="openDisabled"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteEqpMaintainProcessContent"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col>
        </el-row>
        <el-table
          :data="eqpMaintainProcessContentList"
          :row-class-name="rowEqpMaintainProcessContentIndex"
          @selection-change="handleEqpMaintainProcessContentSelectionChange"
          ref="eqpMaintainProcessContent"
        >
          <el-table-column type="selection" width="50" align="center" fixed />
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          />
          <el-table-column label="项目" prop="itemName">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.itemName"
                placeholder="请输入项目"
                :disabled="openDisabled"
                @change="setUserInfo(scope.row)"
              />
            </template>
          </el-table-column>
          <el-table-column label="保养内容" prop="maintainContent">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.maintainContent"
                placeholder="请输入保养内容"
                :disabled="openDisabled"
                @change="setUserInfo(scope.row)"
              />
            </template>
          </el-table-column>
          <el-table-column label="保养情况" prop="maintainResult">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.maintainResult"
                placeholder="请输入保养情况"
                :disabled="openDisabled"
                @change="setUserInfo(scope.row)"
              />
            </template>
          </el-table-column>
          <el-table-column label="养护人" prop="createName">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.createName"
                placeholder=""
                :disabled="true"
              />
            </template>
          </el-table-column>
          <el-table-column label="养护时间" prop="createTime">
            <template slot-scope="scope">
              <el-time-picker
                :editable="false"
                clearable
                size="small"
                v-model="scope.row.createTime"
                format="HH:mm"
                type="datetime"
                value-format="HH:mm"
                placeholder="选择养护时间"
              >
              </el-time-picker>
            </template>
          </el-table-column>
          <template v-if="openDisabled">
            <el-table-column label="检查结果" prop="checkResult">
              <template slot-scope="scope">
                <el-radio-group
                  v-model="scope.row.checkResult"
                  :disabled="true"
                >
                  <el-radio
                    v-for="dict in checkResultOptions"
                    :key="dict.dictValue"
                    :label="dict.dictValue"
                    >{{ dict.dictLabel }}</el-radio
                  >
                </el-radio-group>
              </template>
            </el-table-column>
            <el-table-column label="检查人" prop="checkUser">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.checkUserName"
                  placeholder=""
                  :disabled="true"
                />
              </template>
            </el-table-column>
            <el-table-column label="检查时间" prop="checkTime">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.checkTime"
                  placeholder=""
                  :disabled="true"
                />
              </template>
            </el-table-column>
          </template>
        </el-table>
        <template v-if="openDisabled">
          <el-divider content-position="center">养护验收信息</el-divider>
          <el-row>
            <el-col :span="12">
              <el-form-item label="验收人" prop="checkUserName">
                <el-input v-model="form.checkUserName" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="验收时间" prop="checkTime">
                <el-date-picker
                  :editable="false"
                  clearable
                  size="small"
                  v-model="form.checkTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择验收时间"
                  :disabled="true"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="验收意见" prop="checkOpinion">
                <el-input
                  v-model="form.checkOpinion"
                  placeholder="请输入验收意见"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审批人" prop="checkUserName">
                <el-input v-model="form.leaderCheckName" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="审批时间" prop="leaderCheckTime">
                <el-date-picker
                  :editable="false"
                  clearable
                  size="small"
                  v-model="form.leaderCheckTime"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择部门负责人审批时间"
                  :disabled="true"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="审批意见" prop="leaderCheckOpinion">
                <el-input
                  v-model="form.leaderCheckOpinion"
                  placeholder="请输入部门负责人审批意见"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="养护状态" prop="status">
                <el-select
                  v-model="form.status"
                  placeholder="请选择养护级别"
                  :disabled="true"
                >
                  <el-option
                    v-for="dict in statusOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </template>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProcess,
  getProcess,
  delProcess,
  addProcess,
  updateProcess,
  getPlanToProcess,
} from "@/api/equipment/maintain/process";
import { getFactoryList } from "@/api/equipment/common";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Process",
  components: { Treeselect },
  data() {
    return {
      code: null,
      name: null,
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      // 是否加载遮罩层
      isLoading: false,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedEqpMaintainProcessContent: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 养护过程表格数据
      processList: [],
      // 养护过程内容表格数据
      eqpMaintainProcessContentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 养护级别字典
      levelOptions: [],
      // 养护周期字典
      cycleOptions: [],
      // 养护状态字典
      statusOptions: [],
      // 检查结果字典
      checkResultOptions: [],
      isSparePartsStatus: [],
      // 部门树选项
      deptOptions: undefined,
      daterangeTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        code: null,
        name: null,
        planId: null,
        planIds: null,
        level: null,
        cycle: null,
        status: null,
        maintainPerson: null,
        maintainTime: null,
        factoryId: null,
        maintainDevice: null,
        startTime: null,
        endTime: null,
      },
      statusProcess: [
        { dictLabel: "已完成", dictValue: "02" },
        { dictLabel: "未完成", dictValue: "01" },
      ],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        status: [{ required: true, message: "不能为空", trigger: "blur" }],
        code: [{ max: 200, message: "长度不能超过200字符", trigger: "blur" }],
        name: [
          { required: true, message: "不能为空", trigger: "blur" },
          { max: 200, message: "长度不能超过200字符", trigger: "blur" },
        ],
        planId: [{ required: true, message: "不能为空", trigger: "change" }],
        factoryId: [{ required: true, message: "不能为空", trigger: "blur" }],
        maintainDevice: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        maintainTime: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        outStockId: [{ required: true, message: "不能为空", trigger: "blur" }],
        isSpareParts: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getDicts("maintain_level").then((response) => {
      this.levelOptions = response.data;
    });
    this.getDicts("maintain_cycle").then((response) => {
      this.cycleOptions = response.data;
    });
    this.getDicts("maintain_status").then((response) => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_yes_no").then((response) => {
      this.checkResultOptions = response.data;
      this.isSparePartsStatus = response.data;
    });
    // this.getTreeselect();
    this.getFactory();
  },
  methods: {
    setUserInfo(data) {
      data.createName = this.$store.state.user.nickName;
      // data.createBy = this.$store.state.user.name;
      // data.createTime = this.parseTime(new Date());
    },
    /** 查询部门下拉树结构 */
    getFactory() {
      getFactoryList().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // getTreeselect() {
    //     treeselect().then((response) => {
    //         this.deptOptions = response.data;
    //     });
    // },
    planToProcess(e) {
      this.form.planId = e.value;
      let id = this.form.planId;
      getPlanToProcess(id).then((response) => {
        this.form.level = response.data.level;
        this.form.maintainType = response.data.maintainType;
        this.form.cycle = response.data.cycle;
        this.form.maintainPerson = response.data.maintainPerson;
        this.form.factoryId = response.data.factoryId;
        this.form.maintainDevice = response.data.maintainDevice;
        this.form.deviceName = response.data.deviceName;
        this.eqpMaintainProcessContentList =
          response.data.eqpMaintainProcessContentList;
        this.code = response.data.code;
        this.name = response.data.name;
        if (this.form.maintainTime == null) {
          this.form.code = this.code;
          this.form.name = this.name;
        } else {
          this.form.code = this.code + "-" + this.form.maintainTime;
          this.form.name = this.name + "-" + this.form.maintainTime;
        }
      });
    },
    addTime() {
      if (this.form.code != null && this.form.name != null) {
        this.form.code = this.code + "-" + this.form.maintainTime;
        this.form.name = this.name + "-" + this.form.maintainTime;
      }
    },
    /** 查询养护过程列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeTime && "" != this.daterangeTime) {
        this.queryParams.params["beginTime"] = this.daterangeTime[0];
        this.queryParams.params["endTime"] = this.daterangeTime[1];
      }
      listProcess(this.queryParams).then((response) => {
        this.processList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 养护级别字典翻译
    levelFormat(row, column) {
      return this.selectDictLabel(this.levelOptions, row.level);
    },
    // 养护周期字典翻译
    cycleFormat(row, column) {
      return this.selectDictLabel(this.cycleOptions, row.cycle);
    },
    // 养护状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        name: null,
        planId: null,
        level: null,
        maintainType: null,
        cycle: null,
        status: "02",
        maintainPerson: null,
        maintainTime: null,
        isSpareParts: "N",
        outStockId: null,
        outStockName: null,
        factoryId: null,
        maintainDevice: null,
        startTime: null,
        endTime: null,
        checkUser: null,
        checkTime: null,
        checkOpinion: null,
        leaderCheckName: null,
        leaderCheckTime: null,
        leaderCheckOpinion: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        remark: null,
        planName: null,
        deviceName: null,
        oneCheckOpinion:null,
      };
      this.eqpMaintainProcessContentList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openDisabled = false;
      this.open = true;
      this.title = "添加养护过程";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      getProcess(id).then((response) => {
        this.form = response.data;
        // console.log(this.form);
        this.eqpMaintainProcessContentList =
          response.data.eqpMaintainProcessContentList;
        this.open = true;
        this.title = "修改养护过程";
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;
      const id = row.id || this.ids;
      getProcess(id).then((response) => {
        this.form = response.data;
        // console.log(this.form);
        this.eqpMaintainProcessContentList =
          response.data.eqpMaintainProcessContentList;
        this.open = true;
        this.title = "查看养护过程";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.oneCheckOpinion="检查合格";
      this.$refs["form"].validate((valid) => {

        if (valid) {
          this.form.eqpMaintainProcessContentList =
            this.eqpMaintainProcessContentList;
          if (this.form.id != null) {
            updateProcess(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            const result =
              this.form.status == "02"
                ? "养护结果为【已完成】,提交后将无法修改，是否确认提交？"
                : "养护结果为【未完成】,是否确认提交？";
            this.$confirm(result, "警告", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "error",
            })
              .then(() => {
                this.isLoading = true;
                return addProcess(this.form);
              })
              .then(() => {
                this.msgSuccess("上报成功");
                this.open = false;
                this.getList();
                this.isLoading = false;
              })
              .catch(() => {
                this.isLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除养护过程编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delProcess(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 养护过程内容序号 */
    rowEqpMaintainProcessContentIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 养护过程内容添加按钮操作 */
    handleAddEqpMaintainProcessContent() {
      let obj = {};
      obj.itemName = "";
      obj.maintainContent = "";
      obj.maintainResult = "";
      obj.createName = "";
      obj.createTime = "";
      obj.checkResult = "";
      obj.checkUser = "";
      obj.checkTime = "";
      obj.remark = "";
      this.eqpMaintainProcessContentList.push(obj);
    },
    /** 养护过程内容删除按钮操作 */
    handleDeleteEqpMaintainProcessContent() {
      if (this.checkedEqpMaintainProcessContent.length == 0) {
        this.$alert("请先选择要删除的养护过程内容数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.eqpMaintainProcessContentList.splice(
          this.checkedEqpMaintainProcessContent[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handleEqpMaintainProcessContentSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.eqpMaintainProcessContent.clearSelection();
        this.$refs.eqpMaintainProcessContent.toggleRowSelection(
          selection.pop()
        );
      } else {
        this.checkedEqpMaintainProcessContent = selection;
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "equipment/process/export",
        {
          ...this.queryParams,
        },
        "养护过程" + this.parseTime(new Date()) + ".xlsx"
      );
    },
  },
};
</script>
